FROM ubuntu:latest
MAINTAINER anklean "anklean@huakunsoft.com.cn"

RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN sed -i 's@/# deb-src/@/deb-src/@g' /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update

user root
RUN apt-get install -y net-tools inetutils-ping

SHELL ["/bin/bash", "-c"]

WORKDIR /tmp

# Build tools, and misc supporting tools
RUN apt update && \
    apt install -y build-essential gfortran automake bison flex libtool git  gdb vim wget unzip doxygen

RUN apt install -y language-pack-zh-hans && locale-gen zh_CN.UTF-8
ENV LC_ALL='zh_CN.utf8'

# Python v3.7.6
RUN apt install -y zlib1g-dev libffi-dev libssl-dev && \
    wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz && \
    tar -xf Python-3.7.6.tar.xz && rm Python-3.7.6.tar.xz && \
    mkdir /tmp/Python-3.7.6/build && cd /tmp/Python-3.7.6/build && \
    ../configure --enable-shared --enable-unicode=ucs4 --enable-ipv6 && \
    make -j $(nproc --ignore=2) && \
    make install -j $(nproc --ignore=2) && \
    ldconfig && \
    rm -rfv /tmp/*

# Ensuring Python3.7 is the default version
RUN ln -sf /usr/local/bin/python3.7 /usr/bin/python && \
    ln -sf /usr/local/bin/python3.7-config /usr/local/bin/python-config && \
    # Ensuring python is found, even when program is not looking for "m" suffix
    ln -s python3.7m /usr/local/include/python3.7 && \
    ln -s libpython3.7m.a /usr/local/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7.a

# CMake v3.16.3
RUN git clone  --verbose -n https://gitlab.kitware.com/cmake/cmake.git && \
    mkdir /tmp/cmake/build && cd /tmp/cmake/build && \
    git checkout v3.16.3 && \
    # I may want to revert to an earlier version to see if the list concatenating
    # issue encountered with Pivy remains.
    ../bootstrap --parallel=$(nproc --ignore=2) && \
    make -j $(nproc --ignore=2) && \
    make install -j $(nproc --ignore=2) && \
    rm -rfv /tmp/*

# Boost v1.81.0
RUN apt install -y liblzma-dev && \
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz && \
    tar -xzf boost_1_81_0.tar.gz && rm boost_1_81_0.tar.gz && \
    cd /tmp/boost_1_81_0 && \
    ./bootstrap.sh --with-python=/usr/local/bin/python3 --with-python-root=/usr/local --with-python-version=3.7 && \
    ./b2 -j$(nproc --ignore=2) && \
    ./b2 -j$(nproc --ignore=2) install && \
    rm -rf /tmp/*

# Link libboost_python, so it can be found without it's python version
RUN ln -s /usr/local/lib/libboost_python37.so.1.72.0 /usr/local/lib/libboost_python.so  

RUN apt install -y perl ruby

# Freetype v 2.9.1
RUN wget http://mirror.downloadvn.com/nongnu/freetype/freetype-2.9.1.tar.gz && \
    tar -xzf freetype-2.9.1.tar.gz && rm freetype-2.9.1.tar.gz && \
    cd  /tmp/freetype-2.9.1 && \
    make -j $(nproc --ignore=2) && \
    make -j $(nproc --ignore=2) install && \
    rm -rfv /tmp/*

################
# Clang v9.0.1
RUN git clone -n https://github.com/llvm/llvm-project.git && \
    cd /tmp/llvm-project && git checkout llvmorg-9.0.1 && \
    sed -i '/#include <vector>/a\#include <limits>' /tmp/llvm-project/llvm/utils/benchmark/src/benchmark_register.h&& \
    mkdir /tmp/llvm-project/build && cd /tmp/llvm-project/build && \
    cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=11 ../llvm && \
    make -j $(nproc --ignore=2) && \
    make -j $(nproc --ignore=2) install && \
    rm -rfv /tmp/*
    